public class LinkList {
    public ListNode head;//链表头节点
    public int l;//链表长度
    public LinkList(){
        this.head=new ListNode();
        this.l=0;
    }
    public void clear(){
        this.head=null;
        this.l=0;
    }
    public boolean empty(){
        return this.l==0;
    }
    public void push(int a){
        if(this.head==null){
            this.head.val=a;
            this.head.next=null;
            this.l++;
            return;
        }
        ListNode last=head;
        while (last.next!=null){
            last=last.next;
        }
        last.val=a;
        last.next=null;
        this.l++;
    }
    public int length(){
        return this.l;
    }
    public int remove(int i){
        ListNode cur=this.head;
        for (int j = 0; j < i; j++) {
             cur=cur.next;
        }
        ListNode pre=this.head;
        while (pre.next!=cur){
            pre=pre.next;
        }
        ListNode next=cur.next;
        pre.next=next;
        return cur.val;
    }
}
